﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DNASequencing.core.data.simple;

namespace DNASequencing.core.data
{
    /// <summary>
    /// This class extends abstract AOligonucleotide and adds 
    /// the backward sequence of the original one. It is used
    /// for backward searching.
    /// </summary>
    class BackwardOligonucleotide : AOligonucleotide
    {
        /// <summary>
        /// Original oligonucleotide.
        /// </summary>
        protected Oligonucleotide _seqOriginal;

        /// <summary>
        /// Backward sequence of the original oligonucleotide.
        /// </summary>
        protected String _sBackwardSequence;

        /// <summary>
        /// Creates new backward oligonucleotide.
        /// </summary>
        /// <param name="original">Original object that will be packed into this.</param>
        public BackwardOligonucleotide(Oligonucleotide original) 
            : base(original.getSequence())
        {
            this._seqOriginal = original;
            _sBackwardSequence = turnString(original.getSequence());
        }

        /// <summary>
        /// This overrided method retuns backward sequence instead of the original one.
        /// </summary>
        /// <returns>Returns backward sequence.</returns>
        override public String getSequence()
        {
            return _sBackwardSequence;
        }

        /// <summary>
        /// Turns string.
        /// </summary>
        /// <param name="str">String, that will be turned.</param>
        /// <returns>Returns backward string <code>str</code>.</returns>
        private String turnString(String str)
        {
            String result = "";
            for (int i = (str.Length - 1); i >= 0; --i)
                result += str[i];
            return result;
        }
    }
}
